package com.neusoft.hifly.lock;

// 多线程抢购业务
public class RushOrder {
	// 库存6万
	int i = 60000; // 跟new RushOrder()一样，存储在堆中

	public void order() { // 存放在虚拟机栈中
		i--;
	}

	public static void main(String[] args) throws Exception {
		RushOrder rushOrder = new RushOrder();
		for (int j = 0; j < 6; j++) {
			new Thread(() -> {
				for (int k = 0; k < 10000; k++) {
					rushOrder.order();
				}
			}).start();
		}
		Thread.sleep(5000);
		System.out.println("库存量：" + rushOrder.i); // 结果值为什么不是0?
	}

}